package com.entity;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;


import java.util.Date;
import java.util.HashSet;
import java.util.Set;

@Getter
@Setter
@NoArgsConstructor
@Entity
@Table(name = "EMPLOYEE",uniqueConstraints = {@UniqueConstraint(columnNames = {"EMP_NO"})})
public class Employee {
    @Id
    @Column(name = "EMP_ID")
    private Long empId;

    @Column(name = "EMP_NO", length = 20, nullable = false)
    private String empNo;

    @Column(name = "EMP_NAME", length = 50, nullable = false)
    private String empName;

    @Column(name = "JOB", length = 30, nullable = false)
    private String job;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "MNG_ID")
    private Employee manager;

    @Column(name = "HIRE_DATE", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date hideDate;

    @Column(name = "SALARY", nullable = false)
    private Float salary;

    @Column(name = "IMAGE", length = 1111111, nullable = true)
    @Lob
    private byte[] image;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "DEPT_ID", nullable = false)
    private Department department;

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "empId")
    private Set<Employee> employees = new HashSet<Employee>(0);

    public Employee(Long empId, String empName, String job, Employee manager, Date hideDate, Float salary, Float comm,
                    Department department) {
        this.empId = empId;
        this.empNo = "E" + this.empId;
        this.empName = empName;
        this.job = job;
        this.manager = manager;
        this.hideDate = hideDate;
        this.salary = salary;
        this.department = department;
    }

}
